import 'dart:typed_data';

import 'package:dict_page_view_plugin/dict_page_view_plugin_platform_interface.dart';
import 'package:flutter/cupertino.dart';

typedef MethodHandler = Future<dynamic> Function(String method, Map<String, dynamic> param);

class DictPageViewWidgetController extends ChangeNotifier {
  DictPageViewWidgetController({required this.id}) {
    s_controllers[id] = this;
  }
  static final s_controllers = Map<int, DictPageViewWidgetController>();

  int id;
  MethodHandler? handler;

  loadUrl(int tabIndex, String url) async {
    return await DictPageViewPluginPlatform.instance.loadUrl(id, tabIndex, url);
  }

  changeTab(int tabIndex) async {
    return await DictPageViewPluginPlatform.instance.changeTab(id, tabIndex);
  }

  loadTabs(List<dynamic> info) async {
    return await DictPageViewPluginPlatform.instance.loadTabs(id, info);
  }

  Future<Uint8List?> takePhoto(int tabIndex) async {
    return await DictPageViewPluginPlatform.instance.takePhoto(id, tabIndex);
  }

  setMethodHandler(MethodHandler handler) {
    this.handler = handler;
  }

  @override
  void dispose() {
    s_controllers.remove(id);
    super.dispose();
  }
}